﻿using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;

namespace INNOVACALL.Framework.Common
{
    /// <summary>
    /// Déplacé par LJO dans le Framework , à corriger dans OP_MVC
    /// </summary>
    public static class ConfigFile
    {
        public static List<string> GetSection(this string fullFilePath, string section)
        {
            List<string> ListJquery = new List<string>();
            string filePath = fullFilePath;

            const int maxContent = 10;

            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
            NameValueCollection dataCol = new NameValueCollection();

            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
            fileMap.ExeConfigFilename = filePath;
            Configuration config =
                ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            int i = 0;
            string xmlString = null;
            while (xmlString != null || i < maxContent)
            {
                xmlString = null;
                if (config.GetSection(section + i.ToString()) != null)
                {
                    xmlString = config.GetSection(section + i.ToString()).SectionInformation.GetRawXml();
                    xmlDoc.LoadXml(xmlString);

                    System.Xml.XmlNode nodeList = xmlDoc.ChildNodes[0];
                    ListJquery.Add(nodeList.Attributes[0].Value);
                    //chaineSection.Contains(@"$j^[0-5]?[0-9]$"))
                    //foreach (System.Xml.XmlAttribute attribute in nodeList.Attributes)
                    //if (nodeList.Attributes[0].Value.ToLower() == key.ToLower())

                }
                i++;
            }
            return ListJquery;

        }

    }
}
